﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ATMCommon.ATMConfig
{
    public class ATMConfigImpl
    {
        #region //////////////////// Init ////////////////////
        private static ATMConfigImpl instance;
        public static ATMConfigImpl Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new ATMConfigImpl();
                    instance.LoadATMConfig();
                }

                return instance;
            }
        }

        private IATMConfig mATMConfig = null;
        private ATMConfigImpl()
        {
            if (BasicConfig.GetATMConfigType() == ATMConfigTypeEnum.Registry)
            {
                mATMConfig = new ATMConfigReg();
            }
            else
            {
                mATMConfig = new ATMConfigXML();
            }
        }
        #endregion


        public void ReloadATMConfig()
        {
            LoadATMConfig();
        }

        private void LoadATMConfig()
        {
            #region Config
            mPlatform = mATMConfig.GetStringValue(LATMConfigPath.Config, "Platform", "KAL");
            #endregion

            #region ModeMan
            LoadHeartBeatComponents();
            #endregion
        }
        #region Config
        
        public string mPlatform = string.Empty;
        public string Platform
        {
            get
            {
                return mATMConfig.GetStringValue(LATMConfigPath.Config, "Platform", "KAL");
            }
        }


        #endregion

        #region Mode Manager
        private List<string> mHeartBeatComponents = new List<string>();
        private void LoadHeartBeatComponents()
        {
            mHeartBeatComponents.Clear();
            string components = mATMConfig.GetStringValue(LATMConfigPath.ModeManager, "HeartBeatComponents", "");

            string[] componentArray = components.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            if (componentArray != null)
            {
                mHeartBeatComponents.AddRange(componentArray);
            }
        }

        public List<string> HeartBeatComponents
        {
            get
            {
                return mHeartBeatComponents;
            }
        }


        #endregion
    }
}
